package fitness;

import java.io.Serializable;
import optimizers.ganeat.oscillator.robustfaststrong.ConstantsRobustFSO;
import model.OligoSystemGeneral;

public class RobustFastStrongOscillatorFitness extends Fitness implements
		Serializable {

	private FastStrongOscillatorFitness singleFitnessEvaluator;

	public RobustFastStrongOscillatorFitness() {
		singleFitnessEvaluator = new FastStrongOscillatorFitness();
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public FitnessResult evaluateFitness(OligoSystemGeneral oligoModel) {
		RobustFastStrongOscillatorResult result = new RobustFastStrongOscillatorResult();
		result.standardModel = oligoModel;
		result.results = new FastStrongOscillatorResult[ConstantsRobustFSO.nTests];
		result.tests = new OligoSystemGeneral[ConstantsRobustFSO.nTests];
		result.tests[0] = oligoModel;
		result.results[0] = (FastStrongOscillatorResult) singleFitnessEvaluator
				.evaluateFitness(result.tests[0]);
		for (int i = 1; i < ConstantsRobustFSO.nTests; i++) {
			result.tests[i] = oligoModel.getNoisyVersion();
			result.results[i] = (FastStrongOscillatorResult) singleFitnessEvaluator
					.evaluateFitness(result.tests[i]);
		}
		for (int i = 0; i < ConstantsRobustFSO.nTests; i++) {
			for (int j = i + 1; j < ConstantsRobustFSO.nTests; j++) {
				if (result.results[i].finalResult() < result.results[j]
						.finalResult()) {
					FastStrongOscillatorResult tmp = result.results[i];
					result.results[i] = result.results[j];
					result.results[j] = tmp;
					OligoSystemGeneral tmp1 = result.tests[i];
					result.tests[i] = result.tests[j];
					result.tests[j] = tmp1;
				}
			}
		}
		return result;
	}

	@Override
	public FitnessResult evaluateFitnessSimple(OligoSystemGeneral indiv) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public FitnessResult minFitness(OligoSystemGeneral indiv) {
		RobustFastStrongOscillatorResult result = new RobustFastStrongOscillatorResult();
		result.standardModel = indiv;
		result.results = new FastStrongOscillatorResult[ConstantsRobustFSO.nTests];
		result.tests = new OligoSystemGeneral[ConstantsRobustFSO.nTests];
		for (int i = 0; i < ConstantsRobustFSO.nTests; i++) {
			result.tests[i] = indiv;
			result.results[i] = (FastStrongOscillatorResult) singleFitnessEvaluator
					.minFitness(indiv);
		}
		return result;
	}
}
